const {getBookHttp} = require("../../models/douban-book")
Page({
  data: {
    book:""
  },
  onLoad: async function(options) {
    var res = await getBookHttp()
    let book = [];
    console.log(res.data);
    res.data.forEach(res=>{
      let {coverImage,title,rating} = res;
      let arr = star(rating)
      book.push({
        coverImgUrl:coverImage,
        name:title,
        rating,
        arr
      })
    }) 
    this.setData({
      book,
    })
    console.log(this.data.book);

    // 处理星星
    function star(num){
      var arr =[]
      for(;num>2;num -= 2){
          arr.push(2)
      }
      num = Number(num.toFixed(1));
      arr.push(num);
      return arr
    }
  },
})